<?php

namespace plugin\admin\app\controller;

use support\Request;
use support\Response;
use plugin\admin\app\model\VideoModel;
use plugin\admin\app\controller\Crud;
use support\exception\BusinessException;

/**
 * 视频管理 
 */
class VideoController extends Crud
{
    
    /**
     * @var VideoModel
     */
    protected $model = null;

    /**
     * 构造函数
     * @return void
     */
    public function __construct()
    {
        $this->model = new VideoModel;
    }
    
    /**
     * 浏览
     * @return Response
     */
    public function index(): Response
    {
        return view('video/index');
    }

    /**
     * 查询
     * @param Request $request
     * @return Response
     * @throws BusinessException
     */
    public function select(Request $request): Response
    {
        $request->inputSet('isdel',0);
        $request->inputSet('field','sort');
        return parent::select($request);
    }

    /**
     * 插入
     * @param Request $request
     * @return Response
     * @throws BusinessException
     */
    public function insert(Request $request): Response
    {
        if ($request->method() === 'POST') {
            //获取编号
            $videoSn = $this->getSn('video_sn', '30', 4, 2);
            $request->inputSet('video_sn',$videoSn);
            return parent::insert($request);
        }
        return view('video/insert');
    }

    /**
     * 更新
     * @param Request $request
     * @return Response
     * @throws BusinessException
    */
    public function update(Request $request): Response
    {
        if ($request->method() === 'POST') {
            return parent::update($request);
        }
        return view('video/update');
    }

    /**
     * 删除
     * @param Request $request
     * @return Response
     * @throws BusinessException
     */
    public function delete(Request $request): Response
    {
        $ids = $this->deleteInput($request);
        $this->doIsDelete($ids);
        return $this->json(0);
    }

}
